//
//  ReadTableViewCell.m
//  图片故事
//
//  Created by 刘鉴古 on 16/3/2.
//  Copyright © 2016年 helloApp. All rights reserved.
//

#import "ReadTableViewCell.h"
#import "Header.h"
#import "UIButton+WebCache.h"
#import "UserInfoModal.h"

#define Screen [UIScreen mainScreen].bounds.size

@implementation ReadTableViewCell

// 重写cell初始化方法
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // 创建子视图
        [self setupSubsView];
    }
    return self;
}

- (void)setupSubsView {
    self.contentView.backgroundColor = Bg_Color;
    _headImage = [[UIImageView alloc] init];
    
    _headImage.layer.cornerRadius = My_Height(25);
    _headImage.layer.masksToBounds = YES;

    [self.contentView addSubview:_headImage];
    
    _titleLabel = [[UILabel alloc] init];
    
    [_titleLabel setTextColor:[UIColor whiteColor]];
    
    [_titleLabel setBackgroundColor:Bg_Color];
    
    [self.contentView addSubview:_titleLabel];
    
    _timeLabel = [[UILabel alloc] init];

    _timeLabel.textColor = [UIColor colorWithRed: 158 / 255.0 green: 158 / 255.0 blue: 158 / 255.0 alpha:1.0];
    _timeLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:_timeLabel];
    
    _detailImage = [[UIImageView alloc] init];
    
    [self.contentView addSubview:_detailImage];
    
    _mapImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Map_1.png"]];
    
    [self.contentView addSubview:_mapImage];
    
    _mapLabel = [[UILabel alloc] init];

    _mapLabel.font = [UIFont systemFontOfSize:12];
    
    _mapLabel.textColor = [UIColor colorWithRed:94 / 255.0 green:94 / 255.0 blue:94 / 255.0 alpha:1.0];
    
    [self.contentView addSubview:_mapLabel];
    
    _shareBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    [_shareBtn setBackgroundImage:[UIImage imageNamed:@"Untitled.png"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.shareBtn];
    
    _userHead = [[UIImageView alloc] init];
    
    [_userHead.layer setCornerRadius:My_Height(5)];
    
    [_userHead.layer setMasksToBounds:YES];
    
    [self.contentView addSubview:_userHead];
    
    _detailLabel = [[UITextView alloc] init];
    
    _detailLabel.editable = NO;
    
    [_detailLabel setBackgroundColor:Bg_Color];
    
    _detailLabel.layer.cornerRadius = My_Height(10);
    
    _detailLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.detailLabel];
    
}

- (void)layoutSubviews {

    [super layoutSubviews];
    
    [_headImage setFrame:CGRectMake(My_Height(10), My_Height(20), My_Height(50), My_Height(50))];
    
    [_titleLabel setFrame:CGRectMake(CGRectGetMaxX(self.headImage.frame) + My_Height(10), My_Height(20), SCREEN_W - My_Height(150), My_Height(20))];
    
    [_timeLabel setFrame:CGRectMake(CGRectGetMaxX(self.headImage.frame) + My_Height(10), CGRectGetMaxY(self.titleLabel.frame) + My_Height(10), My_Height(150), My_Height(20))];
    
    [_detailImage setFrame:CGRectMake(0, CGRectGetMaxY(self.headImage.frame) + My_Height(20), Screen.width, Screen.height * 0.47)];
    
    _mapImage.frame = CGRectMake(My_Height(10), CGRectGetMaxY(self.detailImage.frame) + My_Height(12), My_Height(11), My_Height(15));
    
    [_mapLabel setFrame:CGRectMake(CGRectGetMaxX(self.mapImage.frame) + My_Height(8), CGRectGetMaxY(self.detailImage.frame) + My_Height(12), My_Height(200), My_Height(15))];
    
     _shareBtn.frame = CGRectMake(Screen.width - My_Height(41), CGRectGetMaxY(self.detailImage.frame) + My_Height(6),My_Height(26), My_Height(22));
    
    _detailLabel.frame = CGRectMake(My_Height(60), CGRectGetMaxY(self.detailImage.frame) + My_Height(40), Screen.width - My_Height(70), My_Height(170));
    
    [_userHead setFrame:CGRectMake(My_Height(10), CGRectGetMaxY(self.detailImage.frame) + My_Height(40), My_Height(40), My_Height(40))];

}

- (void)setBmobObject:(BmobObject *)bmobObject {

    _bmobObject = bmobObject;
    
    [_titleLabel setText:[_bmobObject objectForKey:@"imageStoryName"]];
    
    [_timeLabel setText:[_bmobObject objectForKey:@"imageStoryTime"]];
    
    [_detailImage sd_setImageWithURL:[NSURL URLWithString:[_bmobObject objectForKey:@"imageStoryImage"]]];
    
    [_mapLabel setText:[_bmobObject objectForKey:@"imageStoryLocation"]];
    
    [_detailLabel setText:[_bmobObject objectForKey:@"imageStoryContext"]];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

@end
